<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.sql.Connection"%>
<%@page import="training.db.Connect"%>
<%@page import="training.data.User"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Starting page</title>
<script language="Javascript">
	function Validate() {
		var user = document.form1.login
		var pass = document.form1.password

		if ((user.value == null) || (user.value == "")) {
			alert("Please Enter user name")
			user.focus()
			return false
		}
		if ((pass.value == null) || (pass.value == "")) {
			alert("Please Enter password")
			pass.focus()
			return false
		}
		return true
	}
</script>
<STYLE TYPE="text/css">
  a:visited{color:green}a:active{color:blue}a:hover{color:magenta}  
</STYLE> 
<link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
</head>
<body  style="margin-top:0;margin-left:0;background-color:white">
<% 
	String login = request.getParameter("login");
	String password = request.getParameter("password");
	Connection conn = Connect.getConnection();
	Integer userId;
	User us = new User(login,password);
	if(login != null && password != null){
		if(login != "" && password != ""){
			if(Connect.findUserByLoginAndPass(conn,us) != null){
				userId = Connect.findUserByLoginAndPass(conn,us);
				session.setAttribute("user",userId.toString());
				session.setAttribute("login",login);
				session.setAttribute("password",password);
				String urls = "welcome.action";
				System.out.println(urls);
				response.sendRedirect(urls);
			};
		}
	}
%>
	<div align="center">
	<table  width="800" style="border: 3px solid #196f99;"
     cellspacing="0"cellpadding="0"rules="none">
	 	<tr>
			<td><!--#054463 font-face:verdana; font-size:12pt; -->
				<img src="Wayden.jpg"align="left"HSPACE=0>
			</td>
		</tr>
		<tr>
			<td><!--#054463 font-face:verdana; font-size:12pt; -->
				<table  width="auto" height="auto" border="0"
                cellspacing="0"cellpadding="0"rules="none">	
					<tr>
			        	<td colspan=2><!--#054463 font-face:verdana; font-size:12pt; -->
				    		<table width="180" height=700  style="background-color: #ebf3fd;">
								<tr>
									<td height="50" width="180" bgcolor="#339999">&nbsp;</td>
								</tr>
								<tr>
									<td colspan=2>&nbsp;</td>
								</tr>
								<tr>
									<td> 
										<form name="form1" action="login.jsp" method="post" onSubmit="return Validate()">
											<table align="center"><tr><td><h2>Login Authentification</h2></td></tr>
											</table>
											<table width="180" align="center" style="background-color: #ebf3fd;">											    										
												<tr>
													<td><b>Login Name</b></td>
													<td><input type="text" name="login" value="" style= "inputbox" width="30"></td>
												</tr>
												<tr>
													<td ><b>Password</b></td>
													<td><input type="password" name="password" value="" style= "inputbox" width="30"></td>
												</tr>
												
												<tr>
													<td></td>
													<td><input type="submit" name="Submit" value="SignIn" style="submitButton" align="left">
													
													</td>
												</tr>																							
												<!--<tr><td colspan=2>&nbsp;</td></tr>-->
											</table>
											<table ><tr><td>
													<p align="left"><font style="font-family:arial, tahoma;font-size:10px;">
														<i>New User?</i>
														</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														&nbsp;
														<font style="font-family:arial, verdana;font-size:12px">
														<a href="registration.jsp" >Register Here</a>
														</font>
											</td></tr></table>
											</form>
                                	</td>																	
								</tr>
								<tr>
									<td height="650" width="180" bgcolor="#339999">&nbsp;</td>
								</tr>
							</table>
			            </td>
						<td height="700" width="700"><!--#054463 font-face:verdana; font-size:12pt; -->
					<form name="frm" action="registration.jsp" method="post"
						onSubmit="return Validate()">
					<table align="center" width="500">
						<tr>
							<td width="500" height="700">&nbsp;
							
							</td>
						</tr>
					</table>
					
					</table>
				 </td>					
			  </td>
		   </tr>					
	     </table>				
      </td>				
   </tr>
   <tr>
	  <td width="800" height="20">
		   <p align="center"><font style="font-family: tahoma;font-size:10px;">
					<i>&copy; Copyright training Антон Lucky Cat, Лиходед Сашка, Микола и Тарас Одинский
					</i>
		   </font>
	  </td>
   </tr>
</table>

</body>
</html>